package com.ruoyi.wgjlcData.service.impl;

import com.alibaba.fastjson2.JSON;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.wgjlcData.domain.plat.DataWgjlcShshl;
import com.ruoyi.wgjlcData.domain.vo.TestOneData;
import com.ruoyi.wgjlcData.mapper.DataWgjlcShshlMapper;
import com.ruoyi.wgjlcData.service.IDataWgjlcShshlService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Async;
import org.springframework.scheduling.annotation.AsyncResult;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.concurrent.Future;


/**
 * 无轨胶轮车-手刹力测试项Service业务层处理
 * 
 * @author ruoyi
 * @date 2024-02-27
 */
@Service
public class DataWgjlcShshlServiceImpl implements IDataWgjlcShshlService
{
    @Autowired
    private DataWgjlcShshlMapper dataWgjlcShshlMapper;

    /**
     * 查询无轨胶轮车-手刹力测试项
     * 
     * @param shshlId 无轨胶轮车-手刹力测试项主键
     * @return 无轨胶轮车-手刹力测试项
     */
    @Override
    public DataWgjlcShshl selectDataWgjlcShshlByShshlId(Long shshlId)
    {
        return dataWgjlcShshlMapper.selectDataWgjlcShshlByShshlId(shshlId);
    }

    /**
     * 查询无轨胶轮车-手刹力测试项列表
     * 
     * @param dataWgjlcShshl 无轨胶轮车-手刹力测试项
     * @return 无轨胶轮车-手刹力测试项
     */
    @Override
    public List<DataWgjlcShshl> selectDataWgjlcShshlList(DataWgjlcShshl dataWgjlcShshl)
    {
        return dataWgjlcShshlMapper.selectDataWgjlcShshlList(dataWgjlcShshl);
    }

    /**
     * 新增无轨胶轮车-手刹力测试项
     * 
     * @param dataWgjlcShshl 无轨胶轮车-手刹力测试项
     * @return 结果
     */
    @Override
    public int insertDataWgjlcShshl(DataWgjlcShshl dataWgjlcShshl)
    {
        dataWgjlcShshl.setCreateTime(DateUtils.getNowDate());
        return dataWgjlcShshlMapper.insertDataWgjlcShshl(dataWgjlcShshl);
    }

    /**
     * 修改无轨胶轮车-手刹力测试项
     * 
     * @param dataWgjlcShshl 无轨胶轮车-手刹力测试项
     * @return 结果
     */
    @Override
    public int updateDataWgjlcShshl(DataWgjlcShshl dataWgjlcShshl)
    {
        dataWgjlcShshl.setUpdateTime(DateUtils.getNowDate());
        //list转Json字符串
        if(!dataWgjlcShshl.getTestOneDataList().isEmpty()) {
            dataWgjlcShshl.setDataList(JSON.toJSONString(dataWgjlcShshl.getTestOneDataList()));
        }
        return dataWgjlcShshlMapper.updateDataWgjlcShshl(dataWgjlcShshl);
    }

    /**
     * 查询无轨胶轮车-手刹力测试项
     *
     * @param dataTaskId
     * @return 无轨胶轮车-手刹力测试项
     */
    @Async("threadPoolKy")
    @Override
    public Future<List<DataWgjlcShshl>> selectDataWgjlcShshlByDataTaskId(Long dataTaskId) {
        List<DataWgjlcShshl> dataWgjlcShshlEntities = dataWgjlcShshlMapper.selectDataWgjlcShshlByDataTaskId(dataTaskId);
        if (dataWgjlcShshlEntities.size() != 0) {
            dataWgjlcShshlEntities.forEach(item -> {
                if (item.getDataList() != null && item.getDataList().length() != 0) {
                    item.setTestOneDataList(JSON.parseArray(item.getDataList(), TestOneData.class));
                    item.setListSize(item.getTestOneDataList().size());
                }
            });
        }
        return new AsyncResult<>(dataWgjlcShshlEntities);
    }

    /**
     * 修改状态为2
     *
     * @param dataTaskId
     */
    @Override
    public int updateDataWgjlcShshlByDataTaskId(Long dataTaskId) {
        return dataWgjlcShshlMapper.updateDataWgjlcShshlByDataTaskId(dataTaskId);
    }

    /**
     * 批量新增无轨胶轮车-手刹力测试项
     *
     * @param dataWgjlcShshl 无轨胶轮车-手刹力测试项
     * @return 结果
     */
    @Override
    public int batchDataWgjlcShshl(List<DataWgjlcShshl> dataWgjlcShshl) {
        return dataWgjlcShshlMapper.batchDataWgjlcShshl(dataWgjlcShshl);
    }

    /**
     * 批量删除无轨胶轮车-手刹力测试项
     * 
     * @param shshlIds 需要删除的无轨胶轮车-手刹力测试项主键
     * @return 结果
     */
    @Override
    public int deleteDataWgjlcShshlByShshlIds(Long[] shshlIds)
    {
        return dataWgjlcShshlMapper.deleteDataWgjlcShshlByShshlIds(shshlIds);
    }

    /**
     * 删除无轨胶轮车-手刹力测试项信息
     * 
     * @param shshlId 无轨胶轮车-手刹力测试项主键
     * @return 结果
     */
    @Override
    public int deleteDataWgjlcShshlByShshlId(Long shshlId)
    {
        return dataWgjlcShshlMapper.deleteDataWgjlcShshlByShshlId(shshlId);
    }
}
